#include "stdafx.h"
#include "Config.h"
#include <boost/lexical_cast.hpp>



void CConfig::load(const std::string &filename)
{
    // Create empty property tree object
    pt::ptree tree;
	pt::ptree configstree;
    // Parse the XML into the property tree.
    pt::read_xml(filename, tree);
	configstree = tree.get_child("configs");
	
    BOOST_FOREACH(pt::ptree::value_type &v, configstree) {

		boost::shared_ptr<stCfg> oneDev(new stCfg());
		oneDev->isnet = v.second.get("isnet", 0);
		if(oneDev->isnet == 0){
			oneDev->name = v.second.get<std::string>("name");
	        oneDev->serial = v.second.get<std::string>("serial");
			oneDev->slave = v.second.get("slave", 1);
			oneDev->devid = oneDev->serial + "-" + boost::lexical_cast<std::string>(oneDev->slave);
		}
		std::cout << oneDev->name <<std::endl;
		m_list.push_back(oneDev);
    }

}

boost::shared_ptr<stCfg> CConfig::find(std::string devid)
{
	for(int i=0; i< m_list.size(); ++i)
	{
		if(m_list[i]->devid == devid)
			return m_list[i];
	}

	return NULL;
}